import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-01-15
 * Time: 10:55
 */
class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        List<List<String>> lists = new ArrayList<List<String>>();
        Map<String , List<String>> map = new HashMap<>();

        for(int i = 0 ; i < strs.length ; i++){
            String curStr = strs[i];
            String change = sort(strs[i]);
            if(map.containsKey(change)){
                //包含
                map.get(change).add(curStr);
            }else{
                //不包含
                List<String> list = new ArrayList<>();
                list.add(curStr);
                map.put(change,list);
            }
        }
        for(Map.Entry<String,List<String>> entry : map.entrySet()){
            lists.add(entry.getValue());
        }
        return lists;

    }

    //给字符串排序
    public String sort(String s){
        char[] ch = s.toCharArray();
        Arrays.sort(ch);
        return String.valueOf(ch);
    }
}
public class Test1 {
}
